-
Notifications
You must be signed in to change notification settings - Fork 6
feat(file-input): Added file input component #1613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with some minor style suggestions.
The main concern is a UX issue with required file inputs. When a user clicks a required file input, the focus shifts to the browser's file dialog. This triggers the input's blur event, which in turn runs the validation logic. This can lead to immediate validation errors being displayed even before the user has selected a file, which is not ideal. To fix this, please implement an internal boolean flag (e.g., _hasActivation
).
Set this flag to true on the input's click event (activation), and reset it to false on the change or cancel events. Then, modify the blur handler to skip validation if _hasActivation
is true.
this.input.value = ''; | ||
this._formValue.value = this._formValue.defaultValue; | ||
|
||
this.requestUpdate(); | ||
this._updateValidity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.input.value = ''; | |
this._formValue.value = this._formValue.defaultValue; | |
this.requestUpdate(); | |
this._updateValidity(); | |
this.input.value = ''; | |
super._restoreDefaultValue(); |
Wouldn't that do the same thing?
if (!this.input) return null; | ||
return this.input.files; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick but it's easier to parse at a glance
if (!this.input) return null; | |
return this.input.files; | |
return this.input?.files ?? null; |
<input | ||
id=${this.inputId} | ||
part=${partNameMap(this.resolvePartNames('input'))} | ||
name=${ifDefined(this.name)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to set a name attribute on the underlying input since it does not participate in form submission
name=${ifDefined(this.name)} |
?multiple=${this.multiple} | ||
tabindex=${this.tabIndex} | ||
accept=${ifDefined(this.accept === '' ? undefined : this.accept)} | ||
aria-invalid=${this.invalid ? 'true' : 'false'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-invalid=${this.invalid ? 'true' : 'false'} | |
aria-invalid=${this.invalid} |
Closes #1581